package ch9.ex4;

import static ch9.print.Print.*;


interface Selector{
	boolean end();
	Object current();
	void next();
}

class Sequence2{
	private Object[] items;
	private int next = 0;
	public Sequence2(int size){
		items = new Object[size];
	}
	public void add(Object x){
		if(next < items.length)
			items[next++] = x;
	}
	private class SequenceSelector implements Selector{
		private int i = 0;
		public boolean end() {return i == items.length;}
		public Object current(){return items[i];}
		public void next() {if(i<items.length) i++;}
		public Sequence2 sequence(){return Sequence2.this;}
	}
	public Selector selector(){
		return new SequenceSelector();
	}
	public boolean check(){
		return this == ((SequenceSelector)selector()).sequence();
	}

}

public class SequenceSelectorToSequence {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Sequence2 s = new Sequence2(10);
		println(s.check());
	}

}
